package it.stasbranger.myproject.client.managed.ui;

import com.google.gwt.core.client.GWT;

import com.google.gwt.dom.client.Element;

import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.HasClickHandlers;

import com.google.gwt.uibinder.client.UiBinder;
import com.google.gwt.uibinder.client.UiField;
import com.google.gwt.uibinder.client.UiHandler;

import com.google.gwt.user.client.Window;

import com.google.gwt.user.client.ui.Composite;
import com.google.gwt.user.client.ui.HTMLPanel;
import com.google.gwt.user.client.ui.Widget;

import it.stasbranger.myproject.client.managed.request.SuppliersProxy;

import it.stasbranger.myproject.client.scaffold.place.ProxyDetailsView;

public class SuppliersMobileDetailsView extends Composite implements
		ProxyDetailsView<SuppliersProxy> {
	interface Binder extends UiBinder<HTMLPanel, SuppliersMobileDetailsView> {
	}

	private static final Binder BINDER = GWT.create(Binder.class);

	private static SuppliersMobileDetailsView instance;

	public static SuppliersMobileDetailsView instance() {
		if (instance == null) {
			instance = new SuppliersMobileDetailsView();
		}
		return instance;
	}

	SuppliersProxy proxy;

	@UiField
	Element idsuppliers;
	@UiField
	Element name;
	@UiField
	Element address;

	@UiField
	Element suppliersHasRequestses;

	@UiField
	HasClickHandlers delete;

	private Delegate delegate;

	public SuppliersMobileDetailsView() {
		initWidget(BINDER.createAndBindUi(this));
	}

	public Widget asWidget() {
		return this;
	}

	public boolean confirm(String msg) {
		return Window.confirm(msg);
	}

	public SuppliersProxy getValue() {
		return proxy;
	}

	@UiHandler("delete")
	public void onDeleteClicked(ClickEvent e) {
		delegate.deleteClicked();
	}

	public void setDelegate(Delegate delegate) {
		this.delegate = delegate;
	}

	public void setValue(SuppliersProxy proxy) {
		this.proxy = proxy;

		idsuppliers.setInnerText(String.valueOf(proxy.getIdsuppliers()));
		name.setInnerText(String.valueOf(proxy.getName()));
		address.setInnerText(String.valueOf(proxy.getAddress()));
		suppliersHasRequestses.setInnerText(proxy.getSuppliersHasRequestses() == null ? "" : it.stasbranger.myproject.client.scaffold.ui.CollectionRenderer.of(SuppliersHasRequestsProxyRenderer.instance()).render(proxy.getSuppliersHasRequestses()));

	}
}
